<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
class Tindex extends Base{
    //主题色
    public function themecolor(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $themecolor['template2']=$customer['template2'];
            if($customer['themefont']==1){  
                $themecolor['themefont']='#000';
            }elseif($customer['themefont']==2){
                $themecolor['themefont']='#fff';
            }
            $themecolor['themecolor']=$customer['themecolor'];
            $themecolor['backcolor']=$customer['backcolor'];
            $themecolor['bottomcolor']=$customer['bottomcolor'];
            return json(['code' => 200, 'msg' => '成功！','data'=>$themecolor]);exit();
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //模块设置
    public function moduleset(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $moduleset=Db::name('tmoduleset')->where('cus_id',$cus_id)->order('id asc')->select();
                if($moduleset){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$moduleset]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $moduleset=Db::name('tmoduleset')->where('cus_id',$cus_id)->order('id asc')->select();
                if($moduleset){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$moduleset]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC关于我们
    public function aboutus(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $taboutus=Db::name('taboutus')->where('cus_id',$cus_id)->find();
            if($taboutus){
                $brandpowers[0]['attr']=$taboutus['attr1'];
                $brandpowers[0]['sattr']=$taboutus['sattr1'];
                $brandpowers[0]['attrimg']=$taboutus['attrimg1'];
                $brandpowers[1]['attr']=$taboutus['attr2'];
                $brandpowers[1]['sattr']=$taboutus['sattr2'];
                $brandpowers[1]['attrimg']=$taboutus['attrimg2'];
                $brandpowers[2]['attr']=$taboutus['attr3'];
                $brandpowers[2]['sattr']=$taboutus['sattr3'];
                $brandpowers[2]['attrimg']=$taboutus['attrimg3'];
                $brandpowers[3]['attr']=$taboutus['attr4'];
                $brandpowers[3]['sattr']=$taboutus['sattr4'];
                $brandpowers[3]['attrimg']=$taboutus['attrimg4'];
                return json(['code' => 200, 'msg' => '成功！','data'=>$taboutus,'brandpowers'=>$brandpowers]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //小程序关于我们
    public function paboutus(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $taboutus=Db::name('taboutus')->where('cus_id',$cus_id)->find();
                if($taboutus){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$taboutus]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $taboutus=Db::name('taboutus')->where('cus_id',$cus_id)->find();
                if($taboutus){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$taboutus]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //wechat底部导航栏
    public function tabBar(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $navs=Db::name('tnav')->where('nav_type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($navs){
                    for ($i=0; $i <count($navs) ; $i++) { 
                        $tabs[$i]['selected']='false';
                        $tabs[$i]['text']=$navs[$i]['nav_name'];
                        $tabs[$i]['pagePath']=$navs[$i]['nav_link'];
                        $tabs[$i]['iconPath']=$navs[$i]['nav_ico'];
                        $tabs[$i]['selectedIconPath']=$navs[$i]['imgt'];
                    }
                    $tabs[0]['selected']='true';
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tabs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $navs=Db::name('tnav')->where('nav_type',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($navs){
                    for ($i=0; $i <count($navs) ; $i++) { 
                        $tabs[$i]['selected']='false';
                        $tabs[$i]['text']=$navs[$i]['nav_name'];
                        $tabs[$i]['pagePath']=$navs[$i]['nav_link'];
                        $tabs[$i]['iconPath']=$navs[$i]['nav_ico'];
                        $tabs[$i]['selectedIconPath']=$navs[$i]['imgt'];
                    }
                    $tabs[0]['selected']='true';
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tabs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //wechat广告
    public function ad(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $ads=Db::name('tbanner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',2)->order('sort desc')->find();
                if($ads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$ads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $ads=Db::name('tbanner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',2)->order('sort desc')->find();
                if($ads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$ads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC导航栏
    public function navs(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $navs=Db::name('tnav')->where('nav_type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($navs){
                return json(['code' => 200, 'msg' => '成功！','data'=>$navs]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pnavs(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $navs=Db::name('tnav')->where('nav_type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($navs){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$navs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $navs=Db::name('tnav')->where('nav_type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($navs){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$navs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC轮播图
    public function banner(){
        Db::name('actives')->insert(['cus_id'=>input("param.cus_id"),'time'=>time()]);
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $tbanners=Db::name('tbanner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',1)->order('sort desc')->select();
            if($tbanners){
                return json(['code' => 200, 'msg' => '成功！','data'=>$tbanners]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pbanner(){
        Db::name('actives')->insert(['cus_id'=>input("param.cus_id"),'time'=>time()]);
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $tbanners=Db::name('tbanner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',1)->order('sort desc')->select();
                if($tbanners){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tbanners]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $tbanners=Db::name('tbanner')->where('cus_id',$cus_id)->where('state',1)->where('mtype',1)->order('sort desc')->select();
                if($tbanners){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tbanners]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //轮播图跳转详情页
    public function bannerdetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.cn"))){
            $cn=input("param.cn");
        }else{
            return json(['code' => 503, 'msg' => '轮播图类型呢']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 504, 'msg' => '轮播图详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if($cn==1){
                $detail=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
            }
            if($cn==2){
                $detail=Db::name('tnews')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
            }
            if($detail){
                return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pbannerdetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.cn"))){
            $cn=input("param.cn");
        }else{
            return json(['code' => 503, 'msg' => '轮播图类型呢']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 504, 'msg' => '轮播图详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){if($cn==1){
                    $detail=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($cn==2){
                    $detail=Db::name('tnews')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($detail){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){if($cn==1){
                    $detail=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($cn==2){
                    $detail=Db::name('tnews')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                }
                if($detail){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
                
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //公告
    public function comad(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $comads=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($comads){
                return json(['code' => 200, 'msg' => '成功！','data'=>$comads]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pcomad(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $comads=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($comads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$comads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $comads=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($comads){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$comads]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //公告跳转详情页
    public function comaddetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '公告详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $detail=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
            if($detail){
                $detail['times']=date('Y-m-d',$detail['time']);
                return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pcomaddetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '公告详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $detail=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['times']=date('Y-m-d',$detail['time']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $detail=Db::name('course')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['times']=date('Y-m-d',$detail['time']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC导师团队
    public function teacherteam(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $teachers=Db::name('teacher')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($teachers){
                return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pteacherteam(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $teachers=Db::name('teacher')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($teachers){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $teachers=Db::name('teacher')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($teachers){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$teachers]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC课程分类
    public function coursecate(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $coursecates=Db::name('tcate')->where('type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($coursecates){
                return json(['code' => 200, 'msg' => '成功！','data'=>$coursecates]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pcoursecate(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $coursecates=Db::name('tcate')->where('type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($coursecates){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$coursecates]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $coursecates=Db::name('tcate')->where('type',2)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($coursecates){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$coursecates]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC分类--课程
    public function catecourse(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.cate_id"))){
            $cate_id=input("param.cate_id");
        }else{
            return json(['code' => 503, 'msg' => '请给出分类id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $courses=Db::name('course')->where('flag',1)->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($courses){
                return json(['code' => 200, 'msg' => '成功！','data'=>$courses]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pcatecourse(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.cate_id"))){
            $cate_id=input("param.cate_id");
        }else{
            return json(['code' => 503, 'msg' => '请给出分类id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $courses=Db::name('course')->where('flag',1)->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($courses){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$courses]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $courses=Db::name('course')->where('flag',1)->where('cate_id',$cate_id)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($courses){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$courses]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC学员风采
    public function student(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $students=Db::name('student')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($students){
                return json(['code' => 200, 'msg' => '成功！','data'=>$students]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function pstudent(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $students=Db::name('student')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($students){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$students]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $students=Db::name('student')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($students){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$students]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC资讯
    public function tnews(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $tnews=Db::name('tnews')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($tnews){
                for ($i=0; $i <count($tnews) ; $i++) {
                    $tnews[$i]['times']=date('Y-m-d',$tnews[$i]['time']);
                    $tnews[$i]['year']=date('Y',$tnews[$i]['time']);
                    $tnews[$i]['monDay']=date('m-d',$tnews[$i]['time']);
                }
                return json(['code' => 200, 'msg' => '成功！','data'=>$tnews]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function ptnews(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $tnews=Db::name('tnews')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($tnews){
                    for ($i=0; $i <count($tnews) ; $i++) {
                        $tnews[$i]['times']=date('Y-m-d',$tnews[$i]['time']);
                        $tnews[$i]['year']=date('Y',$tnews[$i]['time']);
                        $tnews[$i]['monDay']=date('m-d',$tnews[$i]['time']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tnews]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $tnews=Db::name('tnews')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($tnews){
                    for ($i=0; $i <count($tnews) ; $i++) {
                        $tnews[$i]['times']=date('Y-m-d',$tnews[$i]['time']);
                        $tnews[$i]['year']=date('Y',$tnews[$i]['time']);
                        $tnews[$i]['monDay']=date('m-d',$tnews[$i]['time']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$tnews]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //PC环境
    public function envir(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $envirs=Db::name('envir')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
            if($envirs){
                return json(['code' => 200, 'msg' => '成功！','data'=>$envirs]);exit();
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function penvir(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $envirs=Db::name('envir')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($envirs){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$envirs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $envirs=Db::name('envir')->where('flag',1)->where('cus_id',$cus_id)->where('state',1)->order('sort desc')->select();
                if($envirs){
                    return json(['code' => 200, 'msg' => '成功！','data'=>$envirs]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    public function penvirdetail(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '详情id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $detail=Db::name('envir')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['times']=date('Y-m-d',$detail['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $detail=Db::name('envir')->where('cus_id',$cus_id)->where('state',1)->where('id',$id)->find();
                if($detail){
                    $detail['times']=date('Y-m-d',$detail['uptime']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
                
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }



    /**
    *小程序部分
    */
    private function httpRequest($url,$data = null){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    //openID
    public function openid(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.code"))){
            $code=input("param.code");
        }else{
            return json(['code' => 503, 'msg' => '请给code']);exit();
        }
        $taboutus=Db::name('taboutus')->where('cus_id',$cus_id)->find();
        $url="https://api.weixin.qq.com/sns/jscode2session?appid=".$taboutus['appid']."&secret=".$taboutus['appsecret']."&js_code=".$code."&grant_type=authorization_code";
        $res=$this->httpRequest($url);
        if($res){
            return json(['code' => 200, 'msg' => '成功！','data'=>json_decode($res)]);exit();
        }else{
            return json(['code' => 500, 'msg' => '失败！']);exit();
        }
    }

    //如果存在openid不需要保存授权和保存用户信息
    public function isopenid(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => '请给openid']);exit();
        }
        $res=Db::name('users')->where('cus_id',$cus_id)->where('openid',$openid)->find();
        if($res){
            return json(['code' => 200, 'msg' => '存在！']);exit();
        }else{
            return json(['code' => 500, 'msg' => '不存在！']);exit();
        }
    }
    //保存用户信息
    public function userinfoin(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => '请给openid']);exit();
        }
        if(!empty(input("param.avatar"))){
            $avatar=input("param.avatar");
        }else{
            return json(['code' => 504, 'msg' => '请给头像']);exit();
        }
        if(!empty(input("param.nickname"))){
            $nickname=input("param.nickname");
        }else{
            return json(['code' => 505, 'msg' => '请给昵称']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $user=Db::name('users')->where('cus_id',$cus_id)->where('openid',$openid)->find();
                if($user){
                    return json(['code' => 201, 'msg' => '用户已存在！']);exit();
                }else{
                    $data['cus_id']=$cus_id;
                    $data['openid']=$openid;
                    $data['avatar']=$avatar;
                    $data['nickname']=$nickname;
                    $data['time']=time();
                    $userin=Db::name('users')->insert($data);
                    if($userin){
                        return json(['code' => 200, 'msg' => '成功保存用户！']);exit();
                    }else{
                        return json(['code' => 500, 'msg' => '保存失败！']);exit();
                    }
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $user=Db::name('users')->where('cus_id',$cus_id)->where('openid',$openid)->find();
                if($user){
                    return json(['code' => 201, 'msg' => '用户已存在！']);exit();
                }else{
                    $data['cus_id']=$cus_id;
                    $data['openid']=$openid;
                    $data['avatar']=$avatar;
                    $data['nickname']=$nickname;
                    $data['time']=time();
                    $userin=Db::name('users')->insert($data);
                    if($userin){
                        return json(['code' => 200, 'msg' => '成功保存用户！']);exit();
                    }else{
                        return json(['code' => 500, 'msg' => '保存失败！']);exit();
                    }
                }
            }else{
                return json(['code' => 506, 'msg' => '未开启此平台！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //报名的课程和老师
    public function enterct(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '课程id呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $detail=Db::name('course')->alias('a')->join('teacher b', 'a.teacher_id = b.id','LEFT')->field('a.*,b.teacher')->where('a.cus_id',$cus_id)->where('a.state',1)->where('a.id',$id)->find();
                if($detail){
                    $detail['times']=date('Y-m-d',$detail['time']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $detail=Db::name('course')->alias('a')->join('teacher b', 'a.teacher_id = b.id','LEFT')->field('a.*,b.teacher')->where('a.cus_id',$cus_id)->where('a.state',1)->where('a.id',$id)->find();
                if($detail){
                    $detail['times']=date('Y-m-d',$detail['time']);
                    return json(['code' => 200, 'msg' => '成功！','data'=>$detail]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 504, 'msg' => '未开启此平台']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //报名
    public function entercourse(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '课程id呢']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 504, 'msg' => 'openid呢']);exit();
        }
        if(!empty(input("param.name"))){
            $name=input("param.name");
        }else{
            return json(['code' => 505, 'msg' => '学员姓名呢']);exit();
        }
        if(!empty(input("param.phone"))){
            $phone=input("param.phone");
        }else{
            return json(['code' => 506, 'msg' => '联系电话呢']);exit();
        }
        if(!empty(input("param.inviter"))){
            $inviter=input("param.inviter");
        }else{
            return json(['code' => 507, 'msg' => '推荐人呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $enlist=Db::name('enlist')->where('cus_id',$cus_id)->where('openid',$openid)->where('course_id',$id)->find();
                if($enlist){
                    return json(['code' => 201, 'msg' => '您已报过此课程！']);exit();
                }else{
                    $data['cus_id']=$cus_id;
                    $data['course_id']=$id;
                    $data['openid']=$openid;
                    $data['name']=$name;
                    $data['phone']=$phone;
                    $data['inviter']=$inviter;
                    $data['time']=time();
                    $enlistin=Db::name('enlist')->insert($data);
                    if($enlistin){
                        return json(['code' => 200, 'msg' => '报名成功！']);exit();
                    }else{
                        return json(['code' => 500, 'msg' => '报名失败！']);exit();
                    }
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $enlist=Db::name('enlist')->where('cus_id',$cus_id)->where('openid',$openid)->where('course_id',$id)->find();
                if($enlist){
                    return json(['code' => 201, 'msg' => '您已报过此课程！']);exit();
                }else{
                    $data['cus_id']=$cus_id;
                    $data['course_id']=$id;
                    $data['openid']=$openid;
                    $data['name']=$name;
                    $data['phone']=$phone;
                    $data['inviter']=$inviter;
                    $data['time']=time();
                    $enlistin=Db::name('enlist')->insert($data);
                    if($enlistin){
                        return json(['code' => 200, 'msg' => '报名成功！']);exit();
                    }else{
                        return json(['code' => 500, 'msg' => '报名失败！']);exit();
                    }
                }
            }else{
                return json(['code' => 508, 'msg' => '未开启此平台']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //收藏课程
    public function collectcourse(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 503, 'msg' => '课程id呢']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 504, 'msg' => 'openid呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $collect=Db::name('collect')->where('cus_id',$cus_id)->where('openid',$openid)->where('course_id',$id)->find();
            if($collect){
                return json(['code' => 201, 'msg' => '您已收藏此课程！']);exit();
            }else{
                if(input("param.platform")==1&&$customer['platformwx_state']==1){
                    $data['cus_id']=$cus_id;
                    $data['course_id']=$id;
                    $data['openid']=$openid;
                    $data['state']=1;
                    $data['time']=time();
                    $enlistin=Db::name('collect')->insert($data);
                    if($enlistin){
                        return json(['code' => 200, 'msg' => '收藏成功！']);exit();
                    }else{
                        return json(['code' => 500, 'msg' => '收藏失败！']);exit();
                    }
                }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                    $data['cus_id']=$cus_id;
                    $data['course_id']=$id;
                    $data['openid']=$openid;
                    $data['state']=1;
                    $data['time']=time();
                    $enlistin=Db::name('collect')->insert($data);
                    if($enlistin){
                        return json(['code' => 200, 'msg' => '收藏成功！']);exit();
                    }else{
                        return json(['code' => 500, 'msg' => '收藏失败！']);exit();
                    }
                }else{
                return json(['code' => 505, 'msg' => '未开启此平台']);exit();
                }
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //我的报名课程
    public function mycourse(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => 'openid呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $enlists=Db::name('enlist')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('teacher c', 'b.teacher_id = c.id','LEFT')->field('a.id,a.course_id,a.inviter,b.title,b.uptime,c.teacher,c.photo')->where('a.cus_id',$cus_id)->where('a.openid',$openid)->order('a.id desc')->select();
                if($enlists){
                    for ($i=0; $i <count($enlists) ; $i++) { 
                        $enlists[$i]['times']=date('Y-m-d',$enlists[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$enlists]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $enlists=Db::name('enlist')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('teacher c', 'b.teacher_id = c.id','LEFT')->field('a.id,a.course_id,a.inviter,b.title,b.uptime,c.teacher,c.photo')->where('a.cus_id',$cus_id)->where('a.openid',$openid)->order('a.id desc')->select();
                if($enlists){
                    for ($i=0; $i <count($enlists) ; $i++) { 
                        $enlists[$i]['times']=date('Y-m-d',$enlists[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$enlists]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }

    }
    //取消收藏
    public function canclecollect(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => 'openid呢']);exit();
        }
        if(!empty(input("param.id"))){
            $id=input("param.id");
        }else{
            return json(['code' => 504, 'msg' => '收藏id']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            $data['state']=2;
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $collect=Db::name('collect')->where('cus_id',$cus_id)->where('openid',$openid)->where('id',$id)->update($data);
                if($collect){
                    return json(['code' => 200, 'msg' => '成功']);exit();
                }else{
                    return json(['code' => 500, 'msg' => '失败']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $collect=Db::name('collect')->where('cus_id',$cus_id)->where('openid',$openid)->where('id',$id)->update($data);
                if($collect){
                    return json(['code' => 200, 'msg' => '成功']);exit();
                }else{
                    return json(['code' => 500, 'msg' => '失败']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '失败']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }
    }
    //我的收藏课程
    public function mycollect(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => 'openid呢']);exit();
        }
        $customer=Db::name('customer')->where('id',$cus_id)->where('state',1)->find();
        if($customer){
            if(input("param.platform")==1&&$customer['platformwx_state']==1){
                $collect=Db::name('collect')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('teacher c', 'b.teacher_id = c.id','LEFT')->field('a.id,b.title,b.uptime,c.teacher,c.photo')->where('a.cus_id',$cus_id)->where('a.openid',$openid)->where('a.state',1)->order('a.id desc')->select();
                if($collect){
                    for ($i=0; $i <count($collect) ; $i++) { 
                        $collect[$i]['times']=date('Y-m-d',$collect[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$collect]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }elseif(input("param.platform")==2&&$customer['platformbd_state']==1){
                $collect=Db::name('collect')->alias('a')->join('course b', 'a.course_id = b.id','LEFT')->join('teacher c', 'b.teacher_id = c.id','LEFT')->field('a.id,b.title,b.uptime,c.teacher,c.photo')->where('a.cus_id',$cus_id)->where('a.openid',$openid)->where('a.state',1)->order('a.id desc')->select();
                if($collect){
                    for ($i=0; $i <count($collect) ; $i++) { 
                        $collect[$i]['times']=date('Y-m-d',$collect[$i]['uptime']);
                    }
                    return json(['code' => 200, 'msg' => '成功！','data'=>$collect]);exit();
                }else{
                    return json(['code' => 500, 'msg' => '查无数据！']);exit();
                }
            }else{
                return json(['code' => 500, 'msg' => '查无数据！']);exit();
            }
        }else{
            return json(['code' => 502, 'msg' => '此客户不存在或者被禁用了！']);exit();
        }

    }
    //openID
    public function bdopenid(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.code"))){
            $code=input("param.code");
        }else{
            return json(['code' => 503, 'msg' => '请给code']);exit();
        }
        $taboutus=Db::name('taboutus')->where('cus_id',$cus_id)->find();
        $url="https://spapi.baidu.com/oauth/jscode2sessionkey";
        $post_data['code']=$code;
        $post_data['client_id']=$taboutus['bdappkey'];
        $post_data['sk']=$taboutus['bdappsecret'];
        $res=$this->httpRequest($url,$post_data);
        if($res){
            return json(['code' => 200, 'msg' => '成功！','data'=>json_decode($res)]);exit();
        }else{
            return json(['code' => 500, 'msg' => '失败！']);exit();
        }
    }
}